//
//  FourthTableViewCell.m
//  NewMusic
//
//  Created by chuxinyu123 on 15/11/23.
//  Copyright © 2015年 Going. All rights reserved.
//

#import "FourthTableViewCell.h"

#define kWidth self.frame.size.width - 30
@implementation FourthTableViewCell

- (void)dealloc
{
    [_briefLabel release];
    [_firstTitleLabel release];
    [_chineseNameLabel release];
    /*
    [_englishNameLabel release];
    [_countryLabel release];
    [_nationLabel release];
    [_birthDate release];
    [_birthPlaceLabel release];
    [_heightLabel release];
    [_weightLabel release];
    [_bloodTypeLabel release];
    [_schoolLabel release];
    [_careerLabel release];
    [_achievementsLabel release];
     */
    [_secondTitleLabel release];
    [_personalLifeLabel release];
    [_thirdTitleLabel release];
    [_entertainmentExperienceLabel release];
    [_fourthLTitleLabel release];
    [_awardsLabel release];
    [super dealloc];
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self buildSomeLabel];
    }
    return self;
}

- (void)buildSomeLabel
{
    self.briefLabel = [[UILabel alloc] init];
    self.briefLabel.textColor = [UIColor whiteColor];
    self.briefLabel.numberOfLines = 0;
    self.briefLabel.font = [UIFont systemFontOfSize:25];
    self.firstTitleLabel = [[UILabel alloc] init];
    self.firstTitleLabel.textColor = [UIColor whiteColor];
    self.chineseNameLabel = [[UILabel alloc] init];
    self.chineseNameLabel.textColor = [UIColor whiteColor];
    self.chineseNameLabel.numberOfLines = 0;
   
    self.secondTitleLabel = [[UILabel alloc] init];
    self.secondTitleLabel.textColor = [UIColor whiteColor];
    self.personalLifeLabel = [[UILabel alloc] init];
    self.personalLifeLabel.textColor = [UIColor whiteColor];
    self.personalLifeLabel.numberOfLines = 0;
    self.thirdTitleLabel = [[UILabel alloc] init];
    self.thirdTitleLabel.textColor = [UIColor whiteColor];
    self.entertainmentExperienceLabel = [[UILabel alloc] init];
    self.entertainmentExperienceLabel.numberOfLines = 0;
    self.entertainmentExperienceLabel.textColor = [UIColor whiteColor];
    self.fourthLTitleLabel = [[UILabel alloc] init];
    self.fourthLTitleLabel.textColor = [UIColor whiteColor];
    self.awardsLabel = [[UILabel alloc] init];
    self.awardsLabel.textColor = [UIColor whiteColor];
    self.awardsLabel.numberOfLines = 0;
    
    
    [self.contentView addSubview:_briefLabel];
    [self.contentView addSubview:_firstTitleLabel];
    [self.contentView addSubview:_chineseNameLabel];
    
    [self.contentView addSubview:_secondTitleLabel];
    [self.contentView addSubview:_personalLifeLabel];
    [self.contentView addSubview:_thirdTitleLabel];
    [self.contentView addSubview:_entertainmentExperienceLabel];
    [self.contentView addSubview:_fourthLTitleLabel];
    [self.contentView addSubview:_awardsLabel];
    
    [_briefLabel release];
    [_firstTitleLabel release];
    [_chineseNameLabel release];
    [_secondTitleLabel release];
    [_personalLifeLabel release];
    [_thirdTitleLabel release];
    [_entertainmentExperienceLabel release];
    [_fourthLTitleLabel release];
    [_awardsLabel release];
    
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    self.briefLabel.frame = CGRectMake(15, 10, kWidth, [FourthTableViewCell heightWithFont:[UIFont systemFontOfSize:17] andText:_briefLabel.text andWidth:kWidth]);
    self.firstTitleLabel.frame = CGRectMake(15, _briefLabel.frame.size.height + _briefLabel.frame.origin.y + 10, kWidth, 50);
    self.chineseNameLabel.frame = CGRectMake(15, _firstTitleLabel.frame.size.height + _firstTitleLabel.frame.origin.y, kWidth, [FourthTableViewCell heightWithFont:[UIFont systemFontOfSize:17] andText:_chineseNameLabel.text andWidth:kWidth]);
    self.secondTitleLabel.frame = CGRectMake(15, _chineseNameLabel.frame.size.height + _chineseNameLabel.frame.origin.y, kWidth, 50);
    self.personalLifeLabel.frame = CGRectMake(15, _secondTitleLabel.frame.size.height + _secondTitleLabel.frame.origin.y, kWidth, [FourthTableViewCell heightWithFont:[UIFont systemFontOfSize:17] andText:_personalLifeLabel.text andWidth:kWidth]);
    self.thirdTitleLabel.frame = CGRectMake(15, _personalLifeLabel.frame.size.height + _personalLifeLabel.frame.origin.y, kWidth, 50);
    self.entertainmentExperienceLabel.frame = CGRectMake(15, _thirdTitleLabel.frame.size.height + _thirdTitleLabel.frame.origin.y, kWidth, [FourthTableViewCell heightWithFont:[UIFont systemFontOfSize:17] andText:_entertainmentExperienceLabel.text andWidth:kWidth]);
    self.fourthLTitleLabel.frame = CGRectMake(15, _entertainmentExperienceLabel.frame.size.height + _entertainmentExperienceLabel.frame.origin.y, kWidth, 50);
    self.awardsLabel.frame = CGRectMake(15, _fourthLTitleLabel.frame.size.height + _fourthLTitleLabel.frame.origin.y, kWidth, [FourthTableViewCell heightWithFont:[UIFont systemFontOfSize:17] andText:_awardsLabel.text andWidth:kWidth]);
}

+ (CGFloat)heightWithFont:(UIFont *)font andText:(NSString *)text andWidth:(CGFloat)width {
    CGSize size = CGSizeMake(width, MAXFLOAT);
    
    NSDictionary *dictionary = [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName];
    CGRect frame = [text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dictionary context:nil];
    return frame.size.height;
}

- (void)setFourthModel:(FourthModel *)fourthModel
{
    if (_fourthModel != fourthModel) {
        [_fourthModel release];
        _fourthModel = [fourthModel retain];
    }
    _briefLabel.text = fourthModel.birthDate;
    _firstTitleLabel.text = @"档案";
    _firstTitleLabel.font = [UIFont systemFontOfSize:25];
    _chineseNameLabel.text = [NSString stringWithFormat:@"中文名: %@\n外文名: %@\n国 籍: %@\n民 族: %@\n生 日: %@\n出生地: %@\n身 高: %@\n体 重: %@\n血 型: %@\n毕业于: %@\n职 业: %@\n代表作: %@", fourthModel.chineseName, fourthModel.englishName, fourthModel.country, fourthModel.nation, fourthModel.birthDate, fourthModel.birthPlace, fourthModel.height, fourthModel.weight, fourthModel.bloodType, fourthModel.school, fourthModel.career, fourthModel.achievements];
    _secondTitleLabel.text = @"个人生活";
    _secondTitleLabel.font = [UIFont systemFontOfSize:25];
    _personalLifeLabel.text = fourthModel.personalLife;
    _thirdTitleLabel.text = @"演艺经历";
    _thirdTitleLabel.font = [UIFont systemFontOfSize:25];
    _entertainmentExperienceLabel.text = fourthModel.entertainmentExperience;
    _fourthLTitleLabel.text = @"获奖记录";
    _fourthLTitleLabel.font = [UIFont systemFontOfSize:25];
    _awardsLabel.text = fourthModel.awards;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
